home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / asm / fdtools11.lha / fd2i.c < prev    next >
C/C++ Source or Header  |  1994-06-27  |  2KB  |  109 lines

  1. /* fd2i.c - generate .i file with _LVOs from .fd file */
  2.  
  3. #include "fdparse.h"
  4. #include <proto/utility.h>
  5.  
  6. #define BUFFLEN 256
  7.  
  8. extern void addext(STRPTR buff,LONG len,STRPTR orig,STRPTR xt);
  9.  
  10. long __oslibversion = 37;
  11.  
  12. UBYTE verstag[] = "$VER: fd2i 1.1 " __AMIGADATE__ ;
  13.  
  14. UBYTE template[] = "FDFILE/A,IFILE/A";
  15.  
  16. LONG args[2] = { 0, 0};
  17.  
  18. struct Library *UtilityBase;
  19.  
  20. int main(int argc,char **argv)
  21.  
  22. {
  23.   int i;
  24.   int retval = 0;
  25.   struct RDArgs *rda;
  26.   UBYTE buff[BUFFLEN];
  27.   BPTR infile = 0,outfile = 0;
  28.   struct fd fd;
  29.  
  30.   if(argc == 0) return(20); /* we do not run from WB */
  31.  
  32.   UtilityBase = OpenLibrary("utility.library",37);
  33.   if(UtilityBase == 0) return(20);
  34.  
  35.   rda = ReadArgs(template,args,0);
  36.   if(rda) {
  37.     addext(buff,BUFFLEN,(STRPTR)args[0],".fd");
  38.     infile = Open(buff,MODE_OLDFILE);
  39.     if(!infile) {
  40.       Printf("Could not open .fd file !\n");
  41.       retval = 10;
  42.     }
  43.  
  44.     addext(buff,BUFFLEN,(STRPTR)args[1],".i");
  45.     outfile = Open(buff,MODE_NEWFILE);
  46.     if(!outfile) {
  47.       Printf("Could not open .i file !\n");
  48.       retval = 10;
  49.     }
  50.  
  51.     FreeArgs(rda);
  52.   }
  53.   else retval = 10;
  54.  
  55.   if(!retval) {
  56.     FPrintf(outfile,"* %s\n\n",buff);
  57.   
  58.     FPrintf(outfile,"\tIFND\t");
  59.  
  60.     for(i = 0;buff[i];i++) {
  61.       if(buff[i] == '.' || buff[i] == '/') FPutC(outfile,'_');
  62.       else FPutC(outfile,ToUpper(buff[i]));
  63.     }
  64.  
  65.     FPutC(outfile,'\n');
  66.  
  67.     for(i = 0;buff[i];i++) {
  68.       if(buff[i] == '.' || buff[i] == '/') FPutC(outfile,'_');
  69.       else FPutC(outfile,ToUpper(buff[i]));
  70.     }
  71.  
  72.     FPrintf(outfile,"\tSET\t1\n\n");
  73.  
  74.     InitFD(infile,&fd);
  75.  
  76.     do {
  77.       switch(ParseFD(&fd)) {
  78.         case FD_KEYWORD:
  79.           break;
  80.         case FD_FUNCTION:
  81.           if(fd.fd_State & FD_PRIVATE) 
  82.             FPrintf(outfile,"* _LVO%s\tEQU\t%ld\n",
  83.                     fd.fd_Function,fd.fd_Offset);
  84.           else
  85.             FPrintf(outfile,"_LVO%s\tEQU\t%ld\n",
  86.                     fd.fd_Function,fd.fd_Offset);
  87.           break;
  88.         case FD_ERROR:
  89.           Printf("%s\n",fd.fd_Function);
  90.           retval = 10;
  91.           goto error;
  92.         case FD_COMMENT:
  93.           FPrintf(outfile,"%s\n",fd.fd_Function);
  94.           break;
  95.       }
  96.     } while(!(fd.fd_State & FD_READY));
  97.  
  98.     FPrintf(outfile,"\n\tENDC\n");
  99.   }
  100.  
  101. error:
  102.   if(outfile) Close(outfile);
  103.   if(infile) Close(infile);
  104.  
  105.   CloseLibrary(UtilityBase);
  106.  
  107.   return(retval);
  108. }
  109.